package com.ruoyi.web.controller.bookingMiniProgramSettings;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BookingMiniProgramConfig;
import com.ruoyi.system.service.IBookingMiniProgramConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预订小程序设置Controller
 *
 * @author ruoyi
 * @date 2025-05-16
 */
@Api(tags="预订小程序设置")
@RestController
@RequestMapping("/system/bookingMiniProgramConfig")
public class BookingMiniProgramConfigController extends BaseController
{
    @Autowired
    private IBookingMiniProgramConfigService bookingMiniProgramConfigService;

    /**
     * 查询预订小程序设置列表
     */
    @ApiOperation("查询预订小程序设置列表")
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<BookingMiniProgramConfig> list = bookingMiniProgramConfigService.selectBookingMiniProgramConfigListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出预订小程序设置列表
     */
    @ApiOperation("导出预订小程序设置列表")
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @Log(title = "预订小程序设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<BookingMiniProgramConfig> list = bookingMiniProgramConfigService.selectBookingMiniProgramConfigListByName(storeName);
        ExcelUtil<BookingMiniProgramConfig> util = new ExcelUtil<BookingMiniProgramConfig>(BookingMiniProgramConfig.class);
        util.exportExcel(response, list, "预订小程序设置数据");
    }

    /**
     * 通过id获取预订小程序设置详细信息
     */
    @ApiOperation("通过id获取预订小程序设置详细信息")
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bookingMiniProgramConfigService.selectBookingMiniProgramConfigById(id));
    }

    /**
     * 新增预订小程序设置
     */
    @ApiOperation("新增预订小程序设置")
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "预订小程序设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookingMiniProgramConfig bookingMiniProgramConfig)
    {
        return toAjax(bookingMiniProgramConfigService.insertBookingMiniProgramConfig(bookingMiniProgramConfig));
    }

    /**
     * 修改预订小程序设置
     */
    @ApiOperation("修改预订小程序设置")
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "预订小程序设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookingMiniProgramConfig bookingMiniProgramConfig)
    {
        return toAjax(bookingMiniProgramConfigService.updateBookingMiniProgramConfig(bookingMiniProgramConfig));
    }

    /**
     * 通过id批量删除预订小程序设置信息
     */
    @ApiOperation("通过id批量删除预订小程序设置信息")
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "预订小程序设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookingMiniProgramConfigService.deleteBookingMiniProgramConfigByIds(ids));
    }
}
